package com.wangtao.firstapp.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.wangtao.firstapp.R;
import com.wangtao.firstapp.adapters.HomeVPAdapter;
import com.wangtao.firstapp.fragments.personfragments.ArticlesOriginalFragment;
import com.wangtao.firstapp.fragments.personfragments.ShowsFragment;

import java.util.ArrayList;

/**
 * 个人界面  点击  我的原创  跳转到此页面
 * Created by lanouhn on 16/9/19.
 */
public class MyOriginalActivity extends AppCompatActivity {
    private ImageView iv_back_titlebar_myoriginal;// 标题栏返回按钮
    private TabLayout tablayout_myoriginal;
    private ViewPager viewpager_myoriginal;
    private HomeVPAdapter homevpadapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myoriginal);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        iv_back_titlebar_myoriginal = (ImageView) findViewById(R.id.iv_back_titlebar_myoriginal);// 标题返回按钮
        tablayout_myoriginal = (TabLayout) findViewById(R.id.tablayout_myoriginal);
        viewpager_myoriginal = (ViewPager) findViewById(R.id.viewpager_myoriginal);
    }

    private void initData() {
        ArrayList<String> tabnames = new ArrayList<>();
        tabnames.add("文章");
        tabnames.add("晒单");
        ArrayList<Fragment> fragments = new ArrayList<>();
        ArticlesOriginalFragment originalfragment = new ArticlesOriginalFragment();
        ShowsFragment showfragment = new ShowsFragment();
        fragments.add(originalfragment);
        fragments.add(showfragment);
        homevpadapter = new HomeVPAdapter(getSupportFragmentManager(), tabnames, fragments);
        viewpager_myoriginal.setAdapter(homevpadapter);
        tablayout_myoriginal.setupWithViewPager(viewpager_myoriginal);
    }

    private void initEvent() {
        // 返回按钮
        iv_back_titlebar_myoriginal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
